<?php

class ts_framework{

    public function sanitize($string){
        $return = stripslashes($string);
        $return = mysql_real_escape_string($return);
        return $return;
    }

    public function get_query_var($var , $method = 'get' , $sanitize = true){
        $return = '';

        switch($method){
            case 'post' :
                $return = isset($_POST[$var]) ? $_POST[$var] : "";
                break;

            case 'get' :
                $return = isset($_GET[$var]) ? $_GET[$var] : "";
                break;
        }

        if($sanitize){
            $return = $this->sanitize($return);
        }

        return $return;
    }

    public function get_query_string($append = '' , $exclude = null){
        if($exclude == null){
            $exclude = array();
        }

        $new_query = array();
        foreach($_GET as $var => $val){
            if(!in_array($var , $exclude))
                $new_query[] = $var . "=" . $val;
        }

        if($append){
            $new_query[] = $append;
        }

        return implode("&" , $new_query);
    }

    public function store($var , $value = '' , $method = '' , $sanitize = true){
        if(strtolower($method) == 'get' || strtolower($method) == 'post'){
            $this->output[$var] = $this->get_query_var($var , strtolower($method) , $sanitize);
        }else{
            if($sanitize){
                $value = $this->sanitize($value);
            }
            $this->output[$var] = $value;
        }
    }

    public function output($var , $echo = true){
        if(!isset($this->output[$var])){
            return false;
        }

        if($echo){
            echo $this->output[$var];
        }

        return $this->output[$var];
    }

}

?>